import Axios from "axios";
import Mock from '../mock/loginApi';
export const SELECT_USER = "SELECT_USERS";

export function selectUsers(email, pass) {
    console.log("email from user: " + email);
    return async(dispatch, getState) => {
        let response = await Axios.get("/users");
        let result = {
            isSuccess: false
        }
        const _res_data = response.data.data;
        
        for(let i = 0; i < _res_data.length; i++) {
            console.log("email: "+_res_data[i].email);
            if(_res_data[i].email === email && _res_data[i].password === pass) {
                result.isSuccess = true;
                break;
            }
        }
        
        dispatch({
            type: "SELECT_USERS",
            payload: result
        }); 
        
    }
}

export const getUsers = () => (dispatch, getState) => {
    console.log("get users");
    
}